#include <netinet/in.h>
#include <stdlib.h>
#include <netdb.h>
#include "msql_client.h"
#define MAXDATASIZE 200

msqlConn* connect_to_msql(const char *server)
{
	struct hostent *host;
	int sockfd;
	struct sockaddr_in serv_addr;
	msqlConn* conn = (msqlConn*) malloc (sizeof(msqlConn));
	
	if((host=gethostbyname(server))==NULL) {
                herror("gethostbyname出错！");
                return NULL;
        }
	
	if ((sockfd = socket(AF_INET, SOCK_STREAM, 0)) == -1){
                perror("socket 创建出错！");
                return NULL;
        }

	serv_addr.sin_family=AF_INET;
	serv_addr.sin_port=htons(10086);
	serv_addr.sin_addr = *((struct in_addr *)host->h_addr);

	if (connect(sockfd, (struct sockaddr *)&serv_addr, sizeof(struct sockaddr)) == -1) {
		perror("connect出错！");
		return NULL;
	}

	conn->sockfd = sockfd;
	conn->database = NULL;	
	return conn;
} 
